package team119;

import battlecode.common.Direction;
import battlecode.common.GameActionException;
import battlecode.common.MapLocation;
import battlecode.common.RobotController;
import battlecode.common.Team;

public class HelperMethods 
{

	public static void SafeMove(Direction moveDirection, RobotController rc) throws GameActionException
	{
		
			MapLocation newLoc = rc.getLocation().add(moveDirection);
			System.out.println("About to check for mine from current Location:"+rc.getLocation());
			if(rc.senseMine(newLoc)!=null 
					&&rc.senseMine(newLoc)!=rc.getTeam()  )
			{
				while(!rc.isActive()) {
					rc.yield();
				}
				try
				{
					System.out.println("Defusing mine at "+newLoc);
					rc.defuseMine(newLoc);
					return;
				}
				catch(GameActionException ex)
				{
					System.out.println("Exception during safe defuse: "+ex);
					SafeMove(rc.getLocation().directionTo(rc.senseEnemyHQLocation()),rc);
					return;
				}
				
			}
			
			try
			{
				

				System.out.println("Moving towards: "+moveDirection);
				
				if(rc.canMove(moveDirection))
					rc.move(moveDirection);
				else
				{
					System.out.println("Cannot move "+moveDirection);
				}
			}
			catch(GameActionException ex)
			{
				System.out.println("Exception during safe move: "+ex);
				return;
			}
		}
}
